<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/admin/jsp/taglibs.jsp"%>
<html>
	<head>
		<%@ include file="/admin/jsp/header.jsp"%>
		<%@ include file="/framework/jsp/validation.jsp"%>
		<%
			String contextPath=request.getContextPath();
		 %>
	</head>
	<body>
		<table width="98%" border="0" align="center" cellpadding="3" cellspacing="0">
			<tr>
				<td class="page-title">
					<img src="/admin/images/page_title.gif" alt="title" width="17" height="12" align="absmiddle">
					&nbsp;&nbsp; 系统管理 » 号段管理 » 批量载入
				</td>
			</tr>
		</table>
		<br>
		<form id="form" action="/admin/jsp/segmentMgr.do?method=batchSegment" method="POST" target="hidden_frame" enctype="multipart/form-data">
			
				<tr>
					<td><a href="<%=contextPath%>/test.rar">号段文件模板下载</a></td>
				</tr>
				<br>
				<br>
				<br>
				<tr>
					<td valign="top">
						请选择文本文件，文件小于100K<br>									
						<input type="file" id="segmentFile" name="segmentFile" contentEditable="false" size="80"><br>
						<input type="submit" class="short-button" value="载入" onclick="checkFileType()">
						<br><br>
						<iframe name="hidden_frame" id="hidden_frame" style="display:none"></iframe>
						<span id="msg"></span> 
					</td>
				</tr>
			</table>
		</form>
	</body>
	<script language="javascript">
		new Validation('form',{immediate:true});
		
		//验证文件类型
		function checkFileType(){
			var	fileUrl = document.getElementById("segmentFile").value.Trim();
			if(fileUrl == ""){
				alert("请选择一个文件上传！")
				return false;
			}else{
				if(!/\.(txt|TXT)$/.test(fileUrl)){
		          alert("文件格式有误，请重新上传！")
		          return false;
		        }else{
		        	return true;
		        }
			}
		}
	
	//批量载入回调
		function callBack(alertInfo,batchFlag,msg){
			//文件大小不符合要求

			if(msg==""){
				alert(alertInfo);
				return;
			}
			
			if(batchFlag == true)
				alert(alertInfo);
			else{
				if(confirm(alertInfo)){
					document.getElementById("msg").innerHTML = "<textarea rows='15' cols='100' readonly>"+ReplaceAll(msg,"<br>","\n")+"</textarea>";
				}
			}
			document.getElementById("segmentFile").outerHTML = document.getElementById("segmentFile").outerHTML;
		}
		
		//字符替换
		function ReplaceAll(str, sptr, sptr1){
			while (str.indexOf(sptr) >= 0){
			   str = str.replace(sptr, sptr1);
			}
			return str;
		}
	</script>
</html>